/**********************************************************************************
// Achievements Source File
// 
// Creation:	29 Jun 2011
// Updated:		06 Jul 2011
// Compiler:	Visual Studio 2010
//
// Notes:		Achievements manager for game
//
**********************************************************************************/

#include "Achievements.h"

/**********************************************************************************/
// constructor

Achievements::Achievements()
{
	achievementIcons = new Sprite("Resources/AchievementIcons.png", 70, 70, 5);
	
	achievementList[0].points = 10;
	strcpy_s(achievementList[0].name, 40, "Tracer");
	strcpy_s(achievementList[0].description, 80, "Use (T) to turn on the ship path tracer");
	achievementList[0].unlocked = false;

	achievementList[1].points = 10;
	strcpy_s(achievementList[1].name, 40, "Inspector");
	strcpy_s(achievementList[1].description, 50, "Inspect five traces");
	achievementList[1].unlocked = false;

	achievementList[2].points = 20;
	strcpy_s(achievementList[2].name, 40, "Pedal to the Metal");
	strcpy_s(achievementList[2].description, 80, "Finish level 1 in the red without releasing the accelerator");
	achievementList[2].unlocked = false;

	achievementList[3].points = 20;
	strcpy_s(achievementList[3].name, 40, "Redundant");
	strcpy_s(achievementList[3].description, 80, "Finish level 1 after a complete turn around the station");
	achievementList[3].unlocked = false;

	achievementList[4].points = 40;
	strcpy_s(achievementList[4].name, 40, "Left-Right Redundant");
	strcpy_s(achievementList[4].description, 80, "Be redundant once through the right and once through the left");
	achievementList[4].unlocked = false;

	// statistics
	inspector = 0;
	tracer    = 0;
	pedal     = true;
	redundantLeft = false;
	redundantRight = false;
	ZeroMemory(redundantL, sizeof(redundantL));
	ZeroMemory(redundantR, sizeof(redundantR));

	totalPoints = 0;

	animDelay = 4.000f;		// time in seconds
	lastIndex = -1;			// no achievements unlocked
}

/**********************************************************************************/
// destructor

Achievements::~Achievements()
{
	delete achievementIcons;
}

/**********************************************************************************/

void Achievements::Unlock(int index)
{
	
	totalPoints += achievementList[index].points;
	achievementList[index].unlocked = true;
	lastIndex = index;
	
	// the moment the achievement is unlocked
	timer.Start();
}

/**********************************************************************************/
// draw last unlocked achievement

void Achievements::Draw()
{
	if (timer.Elapsed() < animDelay)
	{
		achievementIcons->Draw(lastIndex);
	}
	else
		lastIndex = -1;
}

/**********************************************************************************/
// draw last unlocked achievement

bool Achievements::Waiting()
{
	if (lastIndex >= 0)
		return true;
	else
		return false;
}

/**********************************************************************************/
